---
name: Use github bazel config
description: Uses ci/github/bazelrc, and adds BES config from ci/bes.bazelrc
inputs:
  download_toplevel:
    description: 'whether to download cached toplevel files during bazel builds'
    default: 'false'
  dev:
    description: 'Whether to use DEV or CI settings for the bazelrc. defaults to dev'
    default: 'true'
  BB_API_KEY:
    description: 'API key to use for buildbuddy'
    required: true
runs:
  using: "composite"
  steps:
  - name: Copy github.bazelrc
    run: |
      cp ci/github/bazelrc github.bazelrc
    shell: bash
  - name: Copy BES bazel config
    env:
      BB_API_KEY: ${{ inputs.BB_API_KEY }}
    run: |
      cp ci/bes.bazelrc bes.bazelrc
      echo "build --remote_header=x-buildbuddy-api-key=$BB_API_KEY" >> bes.bazelrc
    shell: bash
  - name: Add remote_download_outputs=toplevel
    if: inputs.download_toplevel == 'true'
    run: |
      echo "build --remote_download_outputs=toplevel" >> github.bazelrc
    shell: bash
  - name: Add DEV settings
    if: inputs.dev == 'true'
    run: |
      echo "build --remote_upload_local_results=false" >> github.bazelrc
      echo "build --build_metadata=ROLE=DEV" >> github.bazelrc
    shell: bash
  - name: Add CI settings
    if: inputs.dev != 'true'
    run: |
      echo "build --build_metadata=ROLE=CI" >> github.bazelrc
    shell: bash
